package com.sdy.dataexchange.meta.job;

import com.sdy.dataexchange.core.schedule.AbstractScheduleJob;
import com.sdy.dataexchange.core.schedule.DynamicScheduler;
import com.sdy.dataexchange.meta.model.MetadataMjMapping;
import com.sdy.dataexchange.meta.service.MetadataMjMappingService;
import com.sdy.dataexchange.meta.service.MetadataModelService;
import org.quartz.JobExecutionContext;

import java.util.List;

/**
 * @author: 王越洋
 * @version: v1.0
 * @description: com.sdy.dataexchange.meta.util
 * @date:2019/11/18
 */
public class ScheduleJob extends AbstractScheduleJob {

    private static MetadataMjMappingService metadataMjMappingService;

    private static MetadataTask metadataTask;

    private static MetadataModelService metadataModelService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        init();
        String jobId = ((DynamicScheduler.JobParameter) jobExecutionContext.getJobDetail().getJobDataMap().
                get(DynamicScheduler.JobParameter.JOB_PARAM)).getJobName();
        List<MetadataMjMapping> metadataMjMappings = metadataMjMappingService.queryByJobId(jobId);
        for (MetadataMjMapping mmm : metadataMjMappings) {
            metadataTask.cloumnComparison(metadataModelService.getById(mmm.getModId()));
        }
    }

    void init() {
        if (metadataMjMappingService == null) {
            metadataMjMappingService = getBean(MetadataMjMappingService.class);
        }
        if (metadataTask == null) {
            metadataTask = getBean(MetadataTask.class);
        }
        if (metadataModelService == null) {
            metadataModelService = getBean(MetadataModelService.class);
        }
    }

//    @Override
//    implements ApplicationContextAware
//    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        metadataModelService = applicationContext.getBean(MetadataModelService.class);
//        metadataMjMappingService = applicationContext.getBean(MetadataMjMappingService.class);
//        metadataTask = applicationContext.getBean(MetadataTask.class);
//    }
}
